package com.whlilong.jxc.db;

import java.util.List;

import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

import com.whlilong.jxc.app.Activator;
import com.whlilong.jxc.service.db.IConnection;

@SuppressWarnings("unchecked")
public class DbManager {

	private static DbManager single = new DbManager();
	private IConnection connect;

	private DbManager() {
		initConnect();
	}

	public static DbManager getInstance() {
		if (single == null)
			single = new DbManager();
		return single;
	}

	public void update(Object obj) {
		connect.update(obj);
	}

	public void insert(Object obj) {
		connect.insert(obj);
	}

	public List search(Object obj) {
		return connect.search(obj);
	}
	public List search(String sql,int[] parameter,Object[] values) {
		return connect.search(sql, parameter, values);
	}

	public List search(String sql,Integer[] parameter,Object[] values) {
		return connect.search(sql, parameter, values);
	}
	
	public void delete(Object obj) {
		connect.delete(obj);
	}

	private void initConnect() {
		BundleContext context = Activator.getDefault().getBundle()
				.getBundleContext();
		ServiceReference service = context
				.getServiceReference(IConnection.class.getName());
		connect = (IConnection) context.getService(service);
	}
	
	public void create(String sql) {
		connect.create(sql);
	}


}
